from manim import *
class CustomCurve(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [120, 8, 0],
            [115,5,0],
            [115,1,0],
            [110,0,0],
            [115,-1,0],
            [115,-5,0],
            [120, -10, 0]
        ]
        self.set_points_smoothly(points)
class CustomCurve1(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [135, 9, 0],
            [130,8,0],
            
            [135, 2, 0]
        ]
        self.set_points_smoothly(points)
class CustomCurve2(VMobject):
    def __init__(self, **kwargs):
        super().__init__(**kwargs)
        # 定义自定义曲线的控制点
        points = [
            [160, 2, 0],
            [170,0,0],
            
            [160, -3, 0]
        ]
        self.set_points_smoothly(points)


class work22(MovingCameraScene):
    def construct(self):
        self.camera.background_color = BLACK  # 设置背景颜色
        self.camera.frame_width = 100  # 设置边框宽度
        self.camera.frame_height = 60  # 设置边框高度
        self.camera.pixel_height = 1080  # 设置像素高度
        self.camera.pixel_width = 1920  # 设置像素宽度
        self.camera.center = ORIGIN  # 设置中心点位置
        self.camera.scale_factor = 1.0  # 设置缩放因子
        self.camera.frame.save_state()
        self.play(self.camera.frame.animate.scale(0.5).move_to([0,0,0]))
        text = Tex(r"$f\left( x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([0,0,0])
        self.play(Write(text))
        text1 = Tex(r"\text{可积？}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text,RIGHT,buff=2)
        self.play(Write(text1))
        text2 = Tex(r"\text{两个条件}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text,RIGHT,buff=2)
        self.play(
            ReplacementTransform(text1,text2)
        )
        self.play(FadeOut(text2),text.animate().shift(20*LEFT))
        self.wait(0.5)
        text3 = Tex(r"\text{有界}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text,RIGHT,buff=2)
        self.play(Write(text3))
        text4 = Tex(r"\text{+}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text3,RIGHT,buff=2)
        self.play(Write(text4))
        text5 = Tex(r"\text{连续}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,RIGHT,buff=2)
        self.play(Write(text5))
        self.play(text5.animate().shift(10*UP))
        text6 = Tex(r"\text{单调}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,RIGHT,buff=2)
        self.play(Write(text6))
        self.play(text6.animate().shift(10*DOWN))
        text7 = Tex(r"\text{有限个间断点}",color=RED
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(text4,RIGHT,buff=2)
        self.play(Write(text7))
        self.play(self.camera.frame.animate.scale(1.5).move_to([0,0,0]))
        #框框
        rectangle=Rectangle(color=BLUE,fill_opacity=0.0,width=17,height=25
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle.move_to([2.5, 0, 0])
        self.play(Create(rectangle))
        text8 = Tex(r"\text{任一}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).next_to(rectangle,UP,buff=1)
        self.play(Write(text8))
        #箭头
        arrow = Arrow(start=[13,0,0],end=[20,0,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow),self.camera.frame.animate.move_to([25,0,0]))
        text9 = Tex(r"$f\left( x\right) $\text{可积}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([25,0,0])
        self.play(Write(text9))
        self.wait(0.3)
         #箭头
        arrow1 = Arrow(start=[33,0,0],end=[40,0,0],color=RED
                       , stroke_width=20, tip_length=1)

        self.play(GrowArrow(arrow1),self.camera.frame.animate.move_to([45,0,0]))
        text9 = Tex(r"$\int _{a}^{x}f\left( t\right) dt$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,0,0])
        self.play(Write(text9))
        self.wait(0.1)
        text90 = Tex(r"\text{存在必连续}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([45,7,0])
        self.play(Write(text90))
        self.wait(0.1)
        #画线
        #下划线
        #下划线+文本
        dot1=Dot([52,0,0])
        dot2=Dot([68,0,0])
        line=Line(dot1,dot2).set_color(GREEN)
        line.set_stroke(width=30)  # 设置宽度为 30
        text10 = Tex(r"$f\left( x\right) $\text{特点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([60,5,0])
        self.play(Create(line),Write(text10),self.camera.frame.animate.move_to([60,0,0]))
        #三个箭头
        arrow2 = Arrow(start=[68,0,0],end=[75,15,0],color=RED
                       , stroke_width=20, tip_length=1)
        arrow3 = Arrow(start=[68,0,0],end=[75,0,0],color=RED
                       , stroke_width=20, tip_length=1)
        arrow4 = Arrow(start=[68,0,0],end=[75,-15,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow2),Create(arrow3),Create(arrow4))
        text11 = Tex(r"\text{性质一}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([80,15,0])
        text12 = Tex(r"\text{性质二}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([80,0,0])
        text13 = Tex(r"\text{性质三}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([80,-15,0])
        self.play(Write(text11),Write(text12),Write(text13))
        self.wait(0.3)
        text14 = Tex(r"\text{周期性：}$f\left( x+T\right) =f\left( x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([100,15,0])
        self.play(Write(text14),self.camera.frame.animate.move_to([100,15,0]))
        self.wait(0.3)
        arrow5 = Arrow(start=[115,15,0],end=[130,15,0],color=RED
                       , stroke_width=20, tip_length=1)
        text15 = Tex(r"$\int _{0}^{T}f\left( t\right) dt=0$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([122,20,0])
        self.play(Create(arrow5),Write(text15),self.camera.frame.animate.move_to([122,15,0]),run_time=1)
        self.wait(0.3)
        text16 = Tex(r"$\int _{a}^{x+T}f\left( t\right) dt=\int _{a}^{x}f\left( t\right) dt$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([145,15,0])
        self.play(Write(text16))
        self.wait(0.3)

        text17 = Tex(r"\text{可导性：}$\int _{a}^{x}t\left( t\right) dt$"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([100,0,0])
        self.play(Write(text17),self.camera.frame.animate.move_to([100,0,0]))
        #括号
        # 添加大括号
        
        curve = CustomCurve(color=RED, stroke_width=20)
        
        # 添加到场景并播放动画
        self.play(Create(curve))
        text18 = Tex(r"\text{可导}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([125, 8, 0])
        text19 = Tex(r"\text{不可导}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([125, -3, 0])
        text20 = Tex(r"\text{未知}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([125, -10, 0])
        self.play(Write(text18),Write(text19),Write(text20),self.camera.frame.animate.move_to([120,0,0]))
        #镜头拉回一点
        self.play(self.camera.frame.animate.scale(1.5))
         # 添加大括号
        
        curve1 = CustomCurve1(color=RED, stroke_width=20)
        # 添加到场景并播放动画
        self.play(Create(curve1))
        text21 = Tex(r"$f\left( x\right) $\text{连续}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([145, 9, 0])
        arrow6 = Arrow(start=[151,9,0],end=[156,9,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Write(text21))
        self.play(Create(arrow6),self.camera.frame.animate.move_to([150,9,0]),run_time=1)
        text22 = Tex(r"$f\left( x\right) $\text{有原函数且}$\left( \int _{a}^{x}f\left( t\right) dt\right) ^{'}=f\left( x\right) $"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([180,9,0])
        self.play(Write(text22))
        text23 = Tex(r"$f\left( x\right) $\text{存在可去间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([147,2,0])
        
        text24 = Tex(r"$f\left( x\right) $\text{存在跳跃间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([147, -3, 0])
        text25 = Tex(r"$f\left( x\right) $\text{存在跳跃间断点}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([147, -10, 0])
        self.play(Write(text23))
        self.play(Write(text24))
        self.play(Write(text25))
        # 添加大括号
        
        curve2 = CustomCurve2(color=RED, stroke_width=20)
        # 添加到场景并播放动画
        self.play(Create(curve2))
        text26 = Tex(r"$f\left( x\right) $\text{没有原函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([180, 0, 0])
        self.play(Write(text26))
        arrow7 = Arrow(start=[161,-10,0],end=[166,-10,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow7))
        text27 = Tex(r"\text{对}$f\left( x\right) $\text{不定积分来判断有无原函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([187, -10, 0])
        self.play(Write(text27))
        text28 = Tex(r"$f\left( x\right) $\text{存在无穷跳跃间断点？}",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([147, -17, 0])
        self.play(Write(text28),self.camera.frame.animate.scale(1.2))
        #框框闪动
        rectangle1=Rectangle(color=BLUE,fill_opacity=0.0,width=20,height=5
                            ,stroke_color=BLUE,stroke_width=20)
        rectangle1.move_to([100,0,0])
        self.play(Create(rectangle1))
        #self.play(FadeOut(rectangle1),FadeOut(text28))

        #曲线箭头
        # 创建一个带有箭头的曲线，让箭头向上凸
        curved_arrow = CurvedArrow(
            start_point=[130, -17, 0],  # 起始点坐标
            end_point=[100,-5,0],  # 终止点坐标
            angle=-PI/4,  # 弯曲的弧度，向上凸#
            tip_shape=StealthTip,  # 箭头类型
            color=BLUE,
            stroke_width=20 
        )
         # 缩放箭头头部
        curved_arrow.tip.scale(10)
        
        # 添加到场景中并播放动画
        self.play(Create(curved_arrow))
        text30 = Tex(r"\text{不存在}",color=GREEN
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([105, -15, 0])
        self.play(Write(text30))

        arrow8 = Arrow(start=[164,-17,0],end=[170,-17,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow8))
        text29 = Tex(r"$f\left( x\right) $\text{没有原函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([180, -17, 0])
        self.play(Write(text29))
        


        text30 = Tex(r"\text{奇偶性：}$f\left( x\right) $\text{为奇函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([88,-25,0])
        self.play(Write(text30),self.camera.frame.animate.move_to([100,-25,0]))
        self.wait(0.3)
        arrow9 = Arrow(start=[102,-25,0],end=[118,-25,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow9))
        text31 = Tex(r"$\int _{a}^{x}f\left( t\right) dt$\text{为偶函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([130,-25,0])
        self.play(Write(text31))

        text32 = Tex(r"$f\left( x\right) $\text{为偶函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([92,-30,0])
        self.play(Write(text32),self.camera.frame.animate.move_to([96,-30,0]))
        self.wait(0.3)
        arrow10 = Arrow(start=[102,-30,0],end=[118,-30,0],color=RED
                       , stroke_width=20, tip_length=1)
        self.play(Create(arrow10))
        text33 = Tex(r"$\int _{0}^{x}f\left( t\right) dt$\text{为奇函数}"
                   ,tex_template=TexTemplateLibrary.ctex).scale(5.0).move_to([130,-30,0])
        self.play(Write(text33))
        arrow11 = Arrow(start=[111,-36,0],end=[119,-32,0],color=PURE_RED
                       , stroke_width=20, tip_length=1)
        self.camera.frame.save_state()
        self.play(Create(arrow11),self.camera.frame.animate.scale(0.6).move_to([118,-32,0]))
        
        
        text34 = Tex(r"$f\left( 0\right) =0$",color=YELLOW
                   ,tex_template=TexTemplateLibrary.ctex).scale(8.0).move_to([114,-40,0])
        self.play(Write(text34))
        self.wait(0.2)
        self.play(Restore(self.camera.frame))

        self.play(self.camera.frame.animate.scale(2).move_to([90,0,0]))
        self.wait()
        self.play(self.camera.frame.animate.scale(0.25).move_to([0,0,0]),run_time=2)
        self.play(self.camera.frame.animate.scale(1).move_to([60,0,0]),run_time=1.5)
        self.play(self.camera.frame.animate.scale(2.5).move_to([90,0,0]),run_time=1)
        self.play(self.camera.frame.animate.scale(1).move_to([150,0,0]),run_time=2)
        self.play(self.camera.frame.animate.scale(1.7).move_to([90,0,0]),run_time=2)


